package com.xjm.ips.controller.system.basic;

import com.xjm.ips.entity.AjaxJson;
import com.xjm.ips.entity.RewardOrPenalty;
import com.xjm.ips.service.RewardOrPenaltyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/basic/rp")
public class RewardOrPenaltyController {
    @Autowired
    RewardOrPenaltyService rewardOrPenaltyService;

    @GetMapping("/")
    public List<RewardOrPenalty> getRewardsOrPenalties(){
        return rewardOrPenaltyService.getRewardsOrPenalties();
    }

    @PutMapping("/")
    public AjaxJson updateRewardOrPenalty(@RequestBody RewardOrPenalty rewardOrPenalty){
        if(rewardOrPenaltyService.updateRewardOrPenalty(rewardOrPenalty)==1){
            return AjaxJson.ok("修改奖罚信息成功!");
        }
        return AjaxJson.error("修改奖罚信息失败!");
    }

    @PostMapping("/")
    public AjaxJson addRewardOrPenalty(@RequestBody RewardOrPenalty rewardOrPenalty){
        if(rewardOrPenaltyService.addRewardOrPenalty(rewardOrPenalty)==1){
            return AjaxJson.ok("新增奖罚信息成功!");
        }
        return AjaxJson.error("新增奖罚信息失败!");
    }

    @DeleteMapping("/{id}")
    public AjaxJson deleteRewardOrPenaltyById(@PathVariable Integer id){
        if(rewardOrPenaltyService.deleteRewardOrPenaltyById(id)==1){
            return AjaxJson.ok("删除奖罚信息成功!");
        }
        return AjaxJson.ok("删除奖罚信息成功!");
    }
}
